﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormExam
{
    public partial class Information : Form
    {
        private int id;

        public Information()
        {
            InitializeComponent();
        }

        private void Information_Load(object sender, EventArgs e)
        {

        }
        public Information(int Id, string Title, string Author, string CreateTime)
        {
            this.id = Id;
            textBox2.Text = Title;
            textBox1.Text = Author;
            textBox3.Text = CreateTime;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            var title = textBox1.Text;
            var author = textBox2.Text;
            var time = textBox3.Text;
            var ids = textBox4.Text;
            var auo = !string.IsNullOrEmpty(author);

            if (auo)
            {
                var sql = string.Format("insert into Articles(Title,Author,CreatedTime)values({0},'{1}','{2}','{3}')", id,title, author, time);

                var dt = DbHelper.AddOrUpdateOrDelete(sql);
                if (dt == 1)
                {
                    DialogResult dr = MessageBox.Show("添加成功", "添加提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.DialogResult = DialogResult.Yes;
                    this.Close();
                }
                else
                {
                    DialogResult dr = MessageBox.Show("添加失败", "添加提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }

        }
        private void button2_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void label4_Click_1(object sender, EventArgs e)
        {

        }
    }
}